<template>
<div>
	<el-col :span="24" class="toolbar" style="padding-bottom: 0px;padding-bottom: 0px;
    display: flex;justify-content: space-between">
			<el-form :inline="true" :model="userSearchDeposit">
				<el-form-item>
					<el-input v-model="userSearchDeposit.uid" :placeholder="$t('iptdefault.username')"></el-input>
				</el-form-item>

        <el-form-item :label="$t('iptdefault.timeselect')">
          <!-- :picker-options="start_date" -->
            <el-col :span="11">
              <el-date-picker type="date"  :placeholder="$t('iptdefault.starttime')" v-model="userSearchDeposit.start" style="width: 100%;"></el-date-picker>
            </el-col>
          
          <el-col class="line" :span="2" style="text-align: center">-</el-col>
          
<!-- :picker-options="end_date" -->
            <el-col :span="11">
              <el-date-picker type="date"  :placeholder="$t('iptdefault.endtime')" v-model="userSearchDeposit.end" style="width: 100%;"></el-date-picker>
            </el-col>

          </el-form-item>

				<el-form-item>
					<el-button type="primary" v-on:click="getUserdeposit">{{$t('publicbtn.query')}}</el-button>
				</el-form-item>

				  <el-form-item>
				<el-button type="primary" @click="userStatusRefresh">{{$t('publicbtn.refresh')}}</el-button>
				</el-form-item>
			</el-form>

       <el-form :inline="true" style="display:flex;align-item:center;">
        <el-form-item>
          <el-button type="primary" @click="exportexcel">{{$t('publicbtn.exportalldata')}}</el-button>
        </el-form-item> 
       <excelexport></excelexport>
      </el-form>

		</el-col>
<!-- 修改数据 -->

  <div class="dealTypeUpdatebox" v-if="userUpdatediposit">
      <div class="dealTypeUpdate">
        <h2>{{$t('withdraw.modify')}}</h2>

        <el-form
          :model="userdatadiposit"
          label-width="100px"
          class="demo-updateForm">
      
              <el-form-item
                label-width="100px"
                label="ID"
                prop="crypto">
                <el-input
                  v-model="userdatadiposit.id"
                readonly></el-input>
              </el-form-item>  

               <el-form-item
                label-width="100px"
                label="TXID"
                prop="crypto">
                <el-input
                  v-model="userdatadiposit.txid"
                  :placeholder="$t('withdraw.txid')"
                ></el-input>
              </el-form-item> 
              
                <el-form-item
                label-width="100px"
                :label="$t('field.comments')"
                prop="crypto" >
                <el-input
                  v-model="userdatadiposit.remark"
                  :placeholder="$t('field.comments')"
                ></el-input>
              </el-form-item>

              <el-form-item
                label-width="100px"
                :label="$t('field.status')"
                prop="status">
                <el-select 
                  v-model="userdatadiposit.status"
                  :placeholder="$t('withdraw.displayed')">
                  <el-option :label="$t('withdraw.withdrawal')" :value="1"></el-option>
                  <el-option :label="$t('withdraw.failure')" :value="-1"></el-option>
                  <el-option :label="$t('withdraw.pleaseselect')" :value="0"></el-option>
                </el-select>
              </el-form-item>
           
          <el-form-item style="text-align: center">
            <el-button type="primary" @click="updatadeposit"
              >{{$t('publicbtn.submitbtn')}}</el-button>
            <el-button @click="resetdeposit">{{$t('publicbtn.cancel')}}</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <!--列表-->
		
			<el-table 
      v-loading="loading"
      :data="depositlist" 
       style="width: 100%;"  
      id="out-table">
			
        	<el-table-column prop="userId"  :label="$t('field.userid')" width="250">
				</el-table-column>

           	<el-table-column prop="username" :label="$t('field.cellphone')" width="250">
				</el-table-column>   
        
        	<el-table-column prop="name" :label="$t('field.upusername')" width="250">
				</el-table-column>

        	<el-table-column prop="inside" :label="$t('withdraw.inside')" width="250">
             <template slot-scope="props">
								{{
								props.row.inside==1?$t('field.yes'):	props.row.inside==0?$t('field.noyes'):''
								}}
							</template>
				</el-table-column>

          	<el-table-column prop="toUserId" :label="$t('withdraw.toUserId')" width="250">
				</el-table-column>
           	<el-table-column prop="toUsername" :label="$t('withdraw.toUsername')" width="250">
				</el-table-column>

             	<el-table-column prop="toName" :label="$t('withdraw.toName')" width="250">
				</el-table-column>


          	<el-table-column prop="crypto" :label="$t('withdraw.currency')" width="250">
				</el-table-column>
            
          <el-table-column prop="num" :label="$t('withdraw.quantity')" width="250">
              <template slot-scope="props">
								{{
								(props.row.num/million).toFixed(8)
								}}
							</template>
				</el-table-column>

					<el-table-column prop="fee" :label="$t('withdraw.withdrawals')" width="250" >
             <template slot-scope="props">
            	{{
								(props.row.fee/million).toFixed(8)
								}}
            </template>
				</el-table-column>

          <el-table-column :label="$t('withdraw.arrivalquantity')" width="250" >
             <template slot-scope="props">
            	{{
								((props.row.num-props.row.fee)/million).toFixed(8)
								}}
            </template>
				</el-table-column>

				  <el-table-column prop="marketValue" :label="$t('withdraw.marketvalue')" width="250">
               <template slot-scope="props">
								{{
								(props.row.marketValue/million).toFixed(8)
								}}
							</template>
				</el-table-column>

      <el-table-column prop="fromAddress" :label="$t('field.sourceaddress')" width="250">

				</el-table-column>
              <el-table-column prop="toAddress" :label="$t('field.destinationaddress')" width="250">
				</el-table-column>

    
           <el-table-column prop="hash" label="hash" width="250">
				</el-table-column>

      <el-table-column prop="referral" :label="$t('field.recommenderId')" width="250"></el-table-column>

					<el-table-column prop="createdAt" :label="$t('field.creationtime')" width="250">
				</el-table-column>

          <el-table-column prop="updateAt" :label="$t('field.upeationtime')" width="250">
				</el-table-column>

    
				<el-table-column :label="$t('field.wallettype')"  width="250"> 
						<template slot-scope="props">
					{{props.row.type==1?$t('field.appWallet'):props.row.type==2?$t('field.otcWallet'):props.row.type==0?'app类型':'' }}
					</template>
				</el-table-column>

        <el-table-column  :label="$t('withdraw.cobotreatment')"  width="250"> 
						<template slot-scope="props">
					{{props.row.cobo==1?$t('field.yes'):props.row.cobo==0?$t('field.no'):'' }}
					</template>
				</el-table-column>
			
        	<el-table-column prop="status" :label="$t('withdraw.withdrawalstatus')" width="250">
            <template slot-scope="props">
            	{{
								props.row.status ==1?$t('withdraw.withdrawal'):props.row.status ==-1?$t('withdraw.failure'):$t('withdraw.inprocess')
								}}
            </template>
				</el-table-column>

          <el-table-column prop="remark" :label="$t('field.remarks')" width="250">
        </el-table-column>
          
          <el-table-column :label="$t('field.operation')" width="110" fixed="right" v-if="diction =='Admin'?true:diction =='Compliance'?true:diction =='CS'?true:diction =='Dealing'?true:diction =='CS_V2'?true:false">
        <template slot-scope="props">
          <el-button size="mini" v-if='props.row.status==1?false:props.row.status==-1?false:true' @click="updataDeposit(props.row.id,props.row.hsah,props.row.remark,props.row.status)">
            {{$t('field.editor')}}
          </el-button>

        </template>
       </el-table-column>
				
			</el-table>

       <!--分页 -->
    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="userdepositTotal"
        :page-size='userSearchDeposit.size'
        @current-change="current_changes"
        :current-page="userSearchDepositCopy.page"
        >
      </el-pagination>
    </div>

</div>

</template>

<script>
import excelexport from "@/components/export.vue";
import exportData from "@/components/export.js";

import { getUserRequest,postUserRequest } from "@/api/api";
export default {
  components:{
        excelexport
  },

  data() {
    return {
      
      // start_date:{//开始时间范围限定
      //           disabledDate:time => {
      //             let _now = Date.now()
      //             let seven = 7 * 24 * 60 * 60 *1000
      //             let sevenDayes = _now - seven
      //             // return time.getTime() > _now || time.getTime() < sevenDayes
                  
      //       if (this.userSearchDeposit.end) {
      //             return time.getTime() > Date.now() || time.getTime() > this.userSearchDeposit.end  
                
      //           } else {
      //             return time.getTime() > Date.now()

      //           }   
      //       }
      //     },
      // end_date:{//结束时间范围限定 userSearchDeposit.start
      //           disabledDate:time => {
      //               return time.getTime() < this.userSearchDeposit.start || time.getTime() > Date.now();
      //      }
      //   },
      million:100000000,
      userUpdatediposit:false,
      userdepositTotal:100,
      loading: true,
      depositlist: [],
      userSearchDeposit:{
        page:1,
        size:10,
        uid:'',
        start:'',
        end:''
      },
      userdatadiposit:{
        id:null,
        remark:null,
        status:null,
        txid:null

      },
      userSearchDepositCopy:{}
    };
  },
      computed:{
      tableData:function(){
    return [[
               this.$t('field.userid'), this.$t('field.cellphone'),   this.$t('field.upusername'),this.$t('withdraw.inside'),this.$t('withdraw.toUserId'),this.$t('withdraw.toUsername'), this.$t('withdraw.toName'),this.$t('withdraw.currency'),   this.$t('withdraw.quantity'),this.$t('withdraw.withdrawals'),this.$t('withdraw.arrivalquantity'),     this.$t('withdraw.marketvalue'),       this.$t('field.sourceaddress'),     this.$t('field.destinationaddress'),'hash',this.$t('field.recommenderId'),this.$t('field.creationtime'), this.$t('field.upeationtime'),this.$t('field.wallettype'),this.$t('withdraw.cobotreatment'),this.$t('withdraw.withdrawalstatus'),this.$t('field.remarks')
 ]]

      }},
  
  methods: {

   
    // 获取用户提现记录
    getUserdeposit(){
        this.userSearchDeposit.page=1
        this.userSearchDepositCopy=JSON.parse(JSON.stringify(this.userSearchDeposit))
        if(this.userSearchDepositCopy.start!='') this.userSearchDepositCopy.start = (new Date(this.userSearchDepositCopy.start)).getTime();
        if(this.userSearchDepositCopy.end!='') this.userSearchDepositCopy.end = (new Date(this.userSearchDepositCopy.end)).getTime();
       this.getUserseposit()
     },

    getUserseposit(){  
         	this.loading=true
          getUserRequest(this.userSearchDepositCopy,'/getWithdrawRecordList').then((res)=>{
            var data =res.data
            if(data.code==200){
                this.depositlist =data.data.list
                this.userdepositTotal = data.data.total
            }else{
              this.$message({
                  message: data.message,
                  type: "error"
                  })
            }
              this.loading=false
            })
    },

 
    // 点击修改
    updataDeposit(id,hash,remark,status){
        this.userUpdatediposit=true
        this.userdatadiposit.id=id
        this.userdatadiposit.txid=hash
        this.userdatadiposit.remark=remark
        this.userdatadiposit.status=status    
    },
    resetdeposit(){
        this.userUpdatediposit=false
    },
    
    //  修改用户体现记录
    updatadeposit(){
      if(this.userdatadiposit.status){
        postUserRequest(this.userdatadiposit,'/updateWithdraw').then((res)=>{
          var data=res.data
          if(data.code==200){
              this.getUserseposit()
          }else{
                this.$message({
              message: data.message,
              type: "error"
              })
          }
        this.userUpdatediposit=false
        })
          }else{
              this.$message({
              message: '请选择状态',
              type: "error"
              })
      }
    },


  // 分页
    current_changes(pager){
        this.userSearchDepositCopy.page=pager
            this.getUserseposit()
    },
    // 刷新
    userStatusRefresh(){
       this.getUserdeposit()
  },
    exportexcel(){
      let tableDatatilte = ['userId','username','name',  'inside',   'toUserId','toUsername', 'toName', 'crypto',     'num',   'fee',       'arrivalquantity','marketValue','fromAddress','toAddress','hash','referral','createdAt','updateAt', 'type',   'cobo',  'status','remark']
      let tableData=this.tableData
      // [[     '用户ID', '手机号',   '用户名称','是否内转','目标用户ID','目标手机号', '目标名称','提现货币',   '提现数量','提现手续费','实际到帐数量',     '市值',       '源地址',     '目标地址',   'hash','创建时间', '更新时间','钱包类型','cobo处理','提现状态','备注']]
      
      let dataMsg =  {start:'',end:'',uid:this.userSearchDeposit.uid,page:1,size:this.million};
      dataMsg.start = JSON.parse(JSON.stringify(this.userSearchDeposit.start));
      dataMsg.end = JSON.parse(JSON.stringify(this.userSearchDeposit.end));
      if(dataMsg.start&&dataMsg.end){
      let _this = this
      if(dataMsg.start !='') dataMsg.start = (new Date(dataMsg.start)).getTime();
      if(dataMsg.end !='') dataMsg.end = (new Date(dataMsg.end)).getTime();
          getUserRequest(dataMsg,'/getWithdrawRecordList').then((res)=>{
      
      let datalist = res.data.data.list
      for(let i = 0;i<datalist.length;i++){
            datalist[i]['num'] = (datalist[i]['num'] / _this.million).toFixed(8)
            datalist[i]['marketValue'] = (datalist[i]['marketValue'] / _this.million).toFixed(8)
            datalist[i]['fee'] = (datalist[i]['fee'] / _this.million).toFixed(8)
            datalist[i]['arrivalquantity'] = (datalist[i]['num']-datalist[i]['fee']).toFixed(8)



             if(datalist[i]['inside'] == 1){
            datalist[i]['inside'] = this.$t('field.yes')
              }else if(datalist[i]['inside'] == 0){
            datalist[i]['inside'] = this.$t('field.noyes')
            }

            if(datalist[i]['type'] == 1){
            datalist[i]['type'] = this.$t('field.appWallet')
              }else if(datalist[i]['type'] == 2){
            datalist[i]['type'] =  this.$t('field.otcWallet')
              }else{
            datalist[i]['type'] =  this.$t('field.appWallet')
              }

            if(datalist[i]['status'] == 1){
            datalist[i]['status'] = this.$t('withdraw.withdrawal')
              }else if(datalist[i]['status'] == -1){
            datalist[i]['status'] =  this.$t('withdraw.failure')
              }else{
            datalist[i]['status'] =  this.$t('withdraw.inprocess')
              }


            if(datalist[i]['cobo'] == 1){
            datalist[i]['cobo'] = this.$t('field.yes')
              }else if(datalist[i]['cobo'] == 0){
            datalist[i]['cobo'] = this.$t('field.no')
              }
         }
            let exportName = this.$t('export.withdrawName')
            exportData.exportTable(datalist,tableData,tableDatatilte,exportName)
           })
        }else{
              this.$message({
            message: this.$t('bulletframe.selecttime'),
            type: "error",
          });
        }
    }
       
  },
  
  created() {

  },
  mounted() {
   
   
    this.diction = sessionStorage.getItem("bospower");

    this.getUserdeposit()},
};
</script>

<style scoped>
.pagination {
  text-align: center;
  margin-top: 20px;
}


.dealTypeUpdate {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 99;
  padding: 20px;
  background: #fff;
  box-shadow: 0px 0px 3px #888;
}
.dealTypeUpdate h2 {
  text-align: center;
  font-size: 18px;
}
.dealTypeUpdatebox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  z-index: 99;
}
</style>